package controllers;

import com.fasterxml.jackson.databind.JsonNode;
import models.User;
import models.utils.Hash;
import play.mvc.*;
import views.html.adminapp.*;
import views.html.login;
import views.html.posapp.*;


/**
 * Created by duzi on 7/2/15.
 */
public class Authenticate extends Controller{
    public Result login(){
        session("loginOrigin", request().path());
        return ok(login.render());
    }
    public Result authenate(){
        JsonNode userjson = request().body().asJson();
        String path = session("loginOrigin");
        User user = User.findById(userjson.get("id").asLong());
        if(user.userPasswd.equals(userjson.get("pass").asText())){
            System.out.println(path);
            if(path.equals("/cashier")){
                return ok("/posapp");
            }else {
                return ok("/adminapp");
            }
        }else{
            return badRequest("no authenticate");
        }
    }
}
